package com.example.anliku.controller;

import com.alibaba.fastjson.JSON;
import com.example.anliku.entity.ExampleKnowledge;
import com.example.anliku.entity.Knowledge;
import com.example.anliku.entity.Message;
import com.example.anliku.entity.clazzBody.clazzRetBody;
import com.example.anliku.entity.clazzBody.clazzRetGxBody;
import com.example.anliku.entity.knowledgeBody.knowledgeRetBody;
import com.example.anliku.entity.knowledgeBody.knowledgeRetGxBody;
import com.example.anliku.service.ExampleKnowledgeService;
import com.example.anliku.service.KnowledgeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "知识点模块")
@RestController
@RequestMapping("/api/knowledge")
public class KnowledgeController {
    @Resource
    private KnowledgeService knowledgeService;

    @Resource
    private ExampleKnowledgeService exampleKnowledgeService;

    @ApiOperation(value = "添加知识点")
    @PostMapping("/one")
    public Message insert(Knowledge knowledge) {
        return knowledgeService.insertSelective(knowledge);
    }

    @ApiOperation(value = "删除知识点")
    @DeleteMapping("/delete")
    public Message delete(Integer knowledgeId ) {
        return knowledgeService.deleteByPrimaryKey(knowledgeId);
    }

    @ApiOperation(value = "删除知识点与案例对应关系")
    @DeleteMapping("/deleteexampleK")
    public Message deleteexampleKnowledge(Integer knowledgeId ) {
        return exampleKnowledgeService.deleteByPrimaryKey(knowledgeId);
    }

    @ApiOperation(value = "修改知识点")
    @PostMapping("/put")
    public Message update(Knowledge knowledge) {
        return knowledgeService.updateByPrimaryKeySelective(knowledge);
    }

    @ApiOperation(value = "获取所有知识点")
    @GetMapping("/all")
    public Message selectAll(){
        return knowledgeService.selectAll();
    }

    @ApiOperation(value = "根据知识点id获取知识点")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer knowledgeId){
        return knowledgeService.selectByPrimaryKey(knowledgeId);
    }


    @ApiOperation(value = "批量添加知识点")
    @PostMapping("/all")
    public Message batchInsert(String list) {
        List<ExampleKnowledge> exampleKnowledgeList = JSON.parseArray(list,ExampleKnowledge.class);
        return exampleKnowledgeService.insertList(exampleKnowledgeList);
    }

    @ApiOperation(value = "批量添加知识点(Body)")
    @PostMapping("/batchInsert")
    public Message batchInsertBody(@RequestBody  List<knowledgeRetBody> list) {
        return exampleKnowledgeService.batchInsertBody(list);
    }

    @ApiOperation(value = "批量添加知识点与案例对应关系(Body)")
    @PostMapping("/listGx")
    public Message batchInsertGx(@RequestBody  List<knowledgeRetGxBody> list) {
        return exampleKnowledgeService.batchInsertGx(list);
    }

}
